<?php

namespace App\Http\Controllers;

use App\Models\Archive;
use App\Models\Category;
use Illuminate\Http\Request;

class ArchiveController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth')->except(['show']);
    }

    public function show(Request $request, Archive  $archive)
    {
        $archive->loadMissing(['category', 'user', 'files', 'tagged']);
        return view('archives.show', compact('archive'));
    }

    public function edit(Request $request, Archive $archive)
    {
        $this->authorize('update', $archive);
        $archive->loadMissing(['category', 'files']);
        return view('archives.edit', compact('archive'));
    }

    public function create(Request $request, Category $category, Archive  $archive)
    {
        $categories = Category::all();
        return view('archives.create', compact('archive', 'categories', 'category'));
    }
}
